package org.kev.transit.worker;

import org.kev.transit.DataActivity;

import android.os.Handler;

public class DataWorker implements Runnable{
	private Handler mCallback=null;
	private DataActivity mParent=null;
	private Runnable mUiUpdater=null;
	/**
	 * 
	 * @param activity
	 * @param callback
	 * @param uiUpdater
	 */
	public DataWorker(DataActivity activity, Handler callback, Runnable uiUpdater){
		init(activity,callback,uiUpdater);
	}
	
	public DataWorker(){
	}
	/**
	 * get ready for run this should be called before the run method
	 * I allow this so the object can be reused in the calling class.  With out
	 * needing to always creat a new instance of the worker object
	 * @param activity
	 * @param callback
	 * @param uiUpdater
	 */
	public void init(DataActivity activity, Handler callback, Runnable uiUpdater){
		mParent=activity;
		mCallback = callback;
		mUiUpdater=uiUpdater;
	}
	public void run(){
		mParent.setData();
		if(mCallback!=null && mUiUpdater!=null)
			mCallback.post(mUiUpdater);
	}
	
}
